package com.exam.project.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.exam.framework.aspectj.lang.annotation.Log;
import com.exam.framework.aspectj.lang.enums.BusinessType;
import com.exam.project.business.domain.PracticeRecord;
import com.exam.project.business.service.IPracticeRecordService;
import com.exam.framework.web.controller.BaseController;
import com.exam.framework.web.domain.AjaxResult;
import com.exam.common.utils.poi.ExcelUtil;
import com.exam.framework.web.page.TableDataInfo;

/**
 * 用户答题Controller
 * 
 * @author qiuwenbing
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/business/practicerecord")
public class PracticeRecordController extends BaseController
{
    @Autowired
    private IPracticeRecordService practiceRecordService;

    /**
     * 查询用户答题列表
     */
    @PreAuthorize("@ss.hasPermi('business:practicerecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(PracticeRecord practiceRecord)
    {
        startPage();
        List<PracticeRecord> list = practiceRecordService.selectPracticeRecordList(practiceRecord);
        return getDataTable(list);
    }

    /**
     * 导出用户答题列表
     */
    @PreAuthorize("@ss.hasPermi('business:practicerecord:export')")
    @Log(title = "用户答题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PracticeRecord practiceRecord)
    {
        List<PracticeRecord> list = practiceRecordService.selectPracticeRecordList(practiceRecord);
        ExcelUtil<PracticeRecord> util = new ExcelUtil<PracticeRecord>(PracticeRecord.class);
        util.exportExcel(response, list, "用户答题数据");
    }

    /**
     * 获取用户答题详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:practicerecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(practiceRecordService.selectPracticeRecordById(id));
    }

    /**
     * 新增用户答题
     */
    @PreAuthorize("@ss.hasPermi('business:practicerecord:add')")
    @Log(title = "用户答题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PracticeRecord practiceRecord)
    {
        return toAjax(practiceRecordService.insertPracticeRecord(practiceRecord));
    }

    /**
     * 修改用户答题
     */
    @PreAuthorize("@ss.hasPermi('business:practicerecord:edit')")
    @Log(title = "用户答题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PracticeRecord practiceRecord)
    {
        return toAjax(practiceRecordService.updatePracticeRecord(practiceRecord));
    }

    /**
     * 删除用户答题
     */
    @PreAuthorize("@ss.hasPermi('business:practicerecord:remove')")
    @Log(title = "用户答题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(practiceRecordService.deletePracticeRecordByIds(ids));
    }
}
